//
//  HYShortTableViewCell.m
//  KaiJing
//
//  Created by lanou on 16/1/14.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYShortTableViewCell.h"
#import "UIView+WLFrame.h"
#import <UIButton+WebCache.h>
@implementation HYShortTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //大的图片
        _shortImageButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _shortImageButton.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight /3);
        _shortImageButton.backgroundColor = kRandomClolor;
        [self.contentView addSubview:_shortImageButton];
        
        //标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _shortImageButton.bottom + 10, kScreenWidth, 30)];
        [self.contentView addSubview:_titleLabel];
        _titleLabel.backgroundColor = kRandomClolor;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        
        //简介
        _synopsisLabel =[[UILabel alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, 60)];
        [self.contentView addSubview:_synopsisLabel];
        _synopsisLabel.backgroundColor = kRandomClolor;
        _synopsisLabel.textAlignment = NSTextAlignmentCenter;
        _synopsisLabel.numberOfLines = -1;
        _synopsisLabel.font = [UIFont systemFontOfSize:15];
        
        //赞
        _praiseButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _praiseButton.frame = CGRectMake(_synopsisLabel.left, _synopsisLabel.bottom + 20, 30, 30);
        _praiseButton.backgroundColor = kRandomClolor;
        [self.contentView addSubview:_praiseButton];
        
        _praiseLabel = [[UILabel alloc] initWithFrame:CGRectMake(_praiseButton.right + 10, _praiseButton.top, _praiseButton.width, _praiseButton.height)];
        _praiseLabel.backgroundColor = kRandomClolor;
        _praiseLabel.text = @"赞";
        [self.contentView addSubview:_praiseLabel];
        
        //评论
        _commentButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _commentButton.frame = CGRectMake(_praiseLabel.right + 10, _synopsisLabel.bottom + 20, 30, 30);
        _commentButton.backgroundColor = kRandomClolor;
        [self.contentView addSubview:_commentButton];
        
        _commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(_commentButton.right + 10, _commentButton.top, 30, 30)];
        _commentLabel.backgroundColor = kRandomClolor;
        _commentLabel.text = @"评论";
        [self.contentView addSubview:_commentLabel];
        
        _moreButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _moreButton.frame = CGRectMake(kScreenWidth - 40, _synopsisLabel.bottom + 20, 30, 30);
        _moreButton.backgroundColor = kRandomClolor;
        [self.contentView addSubview:_moreButton];
        
    }
    return self;
}

- (void) setModel:(HYMoreShortModel *)model {
    _model = model;
    NSString *string = [NSString stringWithFormat:@"http://morguo.com/%@",model.image];
    [_shortImageButton sd_setBackgroundImageWithURL:[NSURL URLWithString:string] forState:(UIControlStateNormal)];
    _titleLabel.text = model.subject;
    _synopsisLabel.text = model.intro;
    
}


+ (CGFloat)labelAndCellHeight:(HYMoreShortModel *)model {
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGRect frame = [model.intro boundingRectWithSize:CGSizeMake(kScreenWidth - 20, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return frame.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
